ninejs.extend(ninejs, function( exports ) {
	function Element(elementData) {
		if (!(this instanceof Element)) {
			return new Element(elementData);
		}

		this.tagName = elementData.tagName;
		this.props = elementData.props;
		this.children = elementData.children;
	}

	Element.prototype = {
		isRealObject: function(obj) {
			return Object.prototype.toString.call(obj) == "[object Object]";
		},
		isElementData: function(data) {
			var props = ["tagName", "props", "children"];
			var flag = true;

			if (this.isRealObject(data)) {
				for (var i = 0; i < props.length; i++) {
					if (!data.hasOwnProperty(props[i])) {
						flag = false;
						break;
					}
				}
			} else {
				flag = false;
			}

			return flag;
		}
	};

	Element.prototype.render = function() {
		var el = document.createElement(this.tagName);

		// props
		var i;
		for (i in this.props) {
			if (this.props.hasOwnProperty(i)) {
				el.setAttribute(i, this.props[i]);
			}
		}

		// children
		var children = this.children || [];
		var child = null;
		for (i = 0; i < children.length; i++) {
			if (typeof(children[i]) == "string") {
				child = document.createTextNode(children[i]);
			} else if (children[i] instanceof Element) {
				child = children[i].render();
			} else if (this.isElementData(children[i])) {
				child = new Element(children[i]);
				child = child.render();
			}
			if (child) {
				el.appendChild(child);
				child = null;
			}
		}

		return el;
	};

	exports.Element = Element;
});